<template>
	<view>
		<view class="padding text-bold text-lg">
			请绑定持卡人本人的银行卡
		</view>
		
		<view class="block">
			<view class="cu-form-group">
				<input placeholder="请输入持卡人姓名" v-model="form.name" name="input"></input>
			</view>
			<view class="cu-form-group">
				<input placeholder="请输入持卡人卡号" v-model="form.card_no" name="input"></input>
			</view>
			<view class="cu-form-group">
				<input placeholder="请输入验证码" name="input" v-model="form.code"></input>
				<button class="cu-btn bg-black shadow" :disabled="num != '验证码'" @click="getCode">{{num}}</button>
			</view>
		</view>
		<view class="padding text-xs">
			说明：请认真核对卡号，确保准确无误
		</view>
		
		
		<view class="add-btn" @click="addBank">确认添加</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flag: 1,
				num: '验证码',
				form: {
					card_no: '',
					name: '',
					code: ''
				}
			}
		},
		onLoad() {
			this.getBank();
		},
		methods: {
			countDown() {
				if (this.flag) {
					this.flag = 0
					this.num = 60
				}
				this.num = this.num - 1
				if (this.num == 0) {
					this.flag = 1
					this.num = '验证码'
					return;
				} else {
					setTimeout(() => {
						this.countDown()
					}, 1000)
				}
			},
			getCode() {
				this.countDown();
				this.$u.post('/passport/getCode', {
					is_login: 1,
					type: 'bankcardadd'
				}).then(res => {
					this.$msg(res.data.msg)
				})
			},
			getBank() {
				uni.showLoading({
					mask: true
				})
				this.$u.get('/user/bank/info').then(res => {
					let data = res.data.result.bank
					if (data) {
						this.form.name = data.name
						this.form.card_no = data.card_no
					}
					
					uni.hideLoading();
				})
			},
			addBank() {
				this.$u.post('/user/bank/info', this.form).then(res => {
					if (res.data.code==0) {
						this.$msg('操作成功')
						setTimeout(() => {
							this.$goto(1)
						}, 500)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
	.block .cu-form-group:nth-last-of-type(1) {
		border-bottom: 1upx solid #eee;
	}

	.add-btn {
		width: 100%;
		height: 100rpx;
		background: #1f1f1f;
		color: white;
		line-height: 100rpx;
		text-align: center;
		font-size: 32rpx;
		letter-spacing: 2rpx;
		position: fixed;
		bottom: 0;
	}
</style>
